const BASE_URL = '/api/services/app/Area'
const API = {
  ALL_PROVINCES: BASE_URL + '/GetProvinces', //所有省份
  ALL_CITYS: BASE_URL + '/GetCities', //所有市
  ALL_AREAS: BASE_URL + '/GetDistricts', //所有县/区
}
export default {
  data() {
    return {
      provinces: [],
      citys: [],
      areas: []
    }
  },
  methods: {
    // 获取所有省份
    getProvinces() {
      this.$axios({
        url: API.ALL_PROVINCES,
        method: "get"
      }).then(res => {
        this.provinces = res.data.result.items;
      })
    },
    // 根据省份获取市
    getCitys(id) {
      this.areas = [];
      this.$axios({
        url: API.ALL_CITYS + "?parentId=" + id,
        method: "get"
      }).then(res => {
        this.citys = res.data.result.items;
      })
    },
    // 获取区或者县
    getAreas(id) {
      this.areas = [];
      this.$axios({
        url: API.ALL_AREAS + "?parentId=" + id,
        data: { parentId: id },
        method: "get"
      }).then(res => {
        this.areas = res.data.result.items;
      })
    }
  },
  mounted() {
    this.getProvinces()
  }
}